/*
 * Geometry.cpp
 *
 *  Created on: 22 juil. 2011
 *      Author: Pierrick Caillon <pierrick@megami.fr>
 */

#include "Geometry.h"
#include <algorithm>

Rect & Rect::Union(const Rect & other)
{
	this->x1 = std::min(this->x1, other.x1);
	this->y1 = std::min(this->y1, other.y1);
	this->x2 = std::max(this->x2, other.x2);
	this->y2 = std::max(this->y2, other.y2);
	return *this;
}

Rect::operator Point() const
{
	return Point(x1, y1);
}

Point & Point::operator +=(const Size & size)
{
	this->x += size.W();
	this->y += size.H();
	return *this;
}

int Point::Y() const
{
	return this->y;
}

Rect::operator Size() const
{
	return Size(this->x2 - this->x1, this->y2 - this->y1);
}

Size Size::operator +(const Size & size) const
{
	return Size(this->w + size.w, this->h + size.h);
}

int Point::X() const
{
	return this->x;
}

int Size::H() const
{
	return this->h;
}

Size & Size::operator =(const Size & size)
{
	this->w = size.w;
	this->h = size.h;
	return *this;
}

Rect & Rect::operator =(const Rect & rect)
{
	this->x1 = rect.x1;
	this->y1 = rect.y1;
	this->x2 = rect.x2;
	this->y2 = rect.y2;
	return *this;
}

Size & Size::operator +=(const Size & size)
{
	this->w += size.w;
	this->h += size.h;
	return *this;
}

int Rect::X() const
{
	return x1;
}

Rect::Rect(int x1, int y1, int x2, int y2)
{
	this->x1 = std::min(x1, x2);
	this->y1 = std::min(y1, y2);
	this->x2 = std::max(x1, x2);
	this->y2 = std::max(y1, y2);
}

int Rect::H() const
{
	return this->y2 - this->y1;
}

Size::Size(int w, int h)
{
	this->w = w;
	this->h = h;
}

Rect & Rect::operator +=(const Point & point)
{
	this->x1 += point.X();
	this->y1 += point.Y();
	this->x2 += point.X();
	this->y2 += point.Y();
	return *this;
}

int Size::W() const
{
	return this->w;
}

int Rect::Y() const
{
	return this->y1;
}

Point::Point()
{
	this->x = 0;
	this->y = 0;
}

Size::Size()
{
	this->w = 0;
	this->h = 0;
}

Point::operator Size() const
{
	return Size(this->x, this->y);
}

Size::Size(const Size & size)
{
	this->w = size.w;
	this->h = size.h;
}

Size::operator Point() const
{
	return Point(this->w, this->h);
}

Point & Point::operator =(const Point & point)
{
	this->x = point.x;
	this->y = point.y;
	return *this;
}

Point Point::operator +(const Size & size) const
{
	return Point(this->x + size.W(), this->y + size.H());
}

Point::Point(const Point & point)
{
	this->x = point.x;
	this->y = point.y;
}

int Rect::W() const
{
	return this->x2 - this->x1;
}

Rect Rect::operator +(const Point & point) const
{
	return Rect(this->x1 + point.X(), this->y1 + point.Y(),
			this->x2 + point.X(), this->y2 + point.Y());
}

Rect::Rect()
{
	this->x1 = 0;
	this->y1 = 0;
	this->x2 = 0;
	this->y2 = 0;
}

Rect::Rect(const Rect & rect)
{
	this->x1 = rect.x1;
	this->y1 = rect.y1;
	this->x2 = rect.x2;
	this->y2 = rect.y2;
}

Rect & Rect::operator +=(const Size & size)
{
	this->x1 = std::min(this->x1, this->x2 + size.W());
	this->y1 = std::min(this->y1, this->y2 + size.H());
	this->x2 = std::max(this->x1, this->x2 + size.W());
	this->y2 = std::max(this->y1, this->y2 + size.H());
	return *this;
}

Rect::Rect(const Point & point, const Size & size)
{
	this->x1 = point.X();
	this->y1 = point.Y();
	this->x2 = point.X() + size.W();
	this->y2 = point.Y() + size.H();
}

Rect Rect::operator +(const Size & size) const
{
	return Rect(this->x1, this->y1, this->x2 + size.W(), this->y2 + size.H());
}

Point::Point(int x, int y)
{
	this->x = x;
	this->y = y;
}

